package com.cqyanyu.yanyu.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;

import com.cqyanyu.yanyu.utils.StatusBarUtil;
import com.cqyanyu.yanyu.view.FontIconView;
import com.umeng.analytics.MobclickAgent;

import org.xutils.x;


/**
 * 基本activiy
 * Created by cheng on 2016/6/13.
 */
@SuppressLint("Registered")
public class XActivity extends Activity {
    protected FontIconView btn_left;
    protected FontIconView btn_right;
    protected FontIconView title;
    private Resources res;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtil.StatusBarLightMode(this);
        x.view().inject(this);
        res = getResources();
        btn_left = (FontIconView) findViewById(res.getIdentifier("btn_left", "id", getPackageName()));
        btn_right = (FontIconView) findViewById(res.getIdentifier("btn_right", "id", getPackageName()));
        title = (FontIconView) findViewById(res.getIdentifier("fi_title", "id", getPackageName()));

    }

    public void setTitle(CharSequence title) {
        if (this.title != null) {
            this.title.setText(title);
        }
    }

    public void setBtn_leftText(CharSequence btn_lefttext) {
        if (btn_left != null) {
            this.btn_left.setText(btn_lefttext);
        }
    }

    public void setBtn_rightText(CharSequence btn_rightText) {
        if (btn_right != null) {
            this.btn_right.setText(btn_rightText);
            this.btn_right.setVisibility(View.VISIBLE);
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);          //统计时长

    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);         //统计时长
    }


    public void onBtnClick(View v) {
        //点击返回键
        if (v.getId() == res.getIdentifier("btn_left", "id", getPackageName())) {
            finish();
        }
    }
}
